home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.exv;
-
- import com.extensibility.util.StringUtilities;
- import com.extensibility.xml.BaseDeclaration;
- import com.extensibility.xml.ExternalSubset;
- import java.io.File;
- import java.io.IOException;
- import java.io.Serializable;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Vector;
-
- public class SchemaStrArray extends MultiModule implements Serializable {
- private static final boolean DEFAULT_PERSISTENT = true;
- private Hashtable schemas;
- private Hashtable used;
-
- public SchemaStrArray(String[] var1, String[] var2) throws SchemaException {
- this(true, var1, var2);
- }
-
- SchemaStrArray(boolean var1, String[] var2, String[] var3) throws SchemaException {
- super(0, var1);
- this.schemas = new Hashtable();
- this.used = new Hashtable();
- this.setSchemas(var2, var3);
- }
-
- public SchemaStrArray(boolean[] var1, String[] var2, String[] var3) throws SchemaException {
- this(true, var1, var2, var3);
- }
-
- SchemaStrArray(boolean var1, boolean[] var2, String[] var3, String[] var4) throws SchemaException {
- super(0, var1);
- this.schemas = new Hashtable();
- this.used = new Hashtable();
- this.setSchemas(var2, var3, var4);
- }
-
- public SchemaStrArray() {
- this(true);
- }
-
- SchemaStrArray(boolean var1) {
- super(0, var1);
- this.schemas = new Hashtable();
- this.used = new Hashtable();
-
- try {
- ((MultiModule)this).setMap(0, true);
- } catch (SchemaException var3) {
- }
-
- }
-
- public void setSchemas(String[] var1, String[] var2) throws SchemaException {
- if (var1 != null && var2 != null) {
- ((MultiModule)this).setMap(var1.length, true);
- ((MultiModule)this).initFileNameMap(var1);
-
- try {
- this.initSchemas(var1, var2);
- } catch (Exception var4) {
- throw new SchemaException("Could not create multi modules of schema", var4);
- }
- } else {
- throw new SchemaException("Invalid schemas");
- }
- }
-
- public void setSchemas(boolean[] var1, String[] var2, String[] var3) throws SchemaException {
- if (var1 != null && var2 != null && var3 != null) {
- ((MultiModule)this).setMap(var1);
- ((MultiModule)this).initFileNameMap(var2);
-
- try {
- this.initSchemas(var1, var2, var3);
- } catch (Exception var5) {
- throw new SchemaException("Could not create multi modules of schema", var5);
- }
- } else {
- throw new SchemaException("Invalid schemas");
- }
- }
-
- public int countFlavor(String var1) {
- Enumeration var2 = this.schemas.keys();
- int var3 = 0;
-
- while(var2.hasMoreElements()) {
- String var4 = (String)var2.nextElement();
- if (var4.toLowerCase().endsWith(String.valueOf(".").concat(String.valueOf(var1.toLowerCase())))) {
- ++var3;
- }
- }
-
- return var3;
- }
-
- public Vector getSchemas() {
- return this.getSchemas(this.schemas);
- }
-
- public SchemaWrapper getSchema(String var1) {
- SchemaWrapper var2;
- return (var2 = (SchemaWrapper)this.schemas.get(var1)) == null ? null : var2;
- }
-
- public void validate() {
- super.validValues = new Hashtable();
- super.wfValues = new Hashtable();
- super.errors = new Hashtable();
- Enumeration var1 = this.schemas.keys();
-
- while(var1.hasMoreElements()) {
- String var2 = (String)var1.nextElement();
- if (!this.used.containsKey(var2)) {
- try {
- this.validate(var2);
- } catch (Exception var4) {
- }
- }
- }
-
- }
-
- public void validate(String var1) throws SchemaException {
- if (var1 == null) {
- throw new SchemaException("Cannot validate a null schema");
- } else if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- if (!this.used.containsKey(var1)) {
- SchemaWrapper var2 = (SchemaWrapper)this.schemas.get(var1);
- this.validateSchema(var1, var2);
- }
-
- }
- }
-
- public boolean isValid() throws SchemaException {
- if (((MultiModule)this).isEmpty()) {
- throw new SchemaException("There are no schemas in the archive");
- } else {
- Vector var1 = this.getSchemas();
-
- for(int var2 = 0; var2 < var1.size(); ++var2) {
- SchemaWrapper var3 = (SchemaWrapper)var1.elementAt(var2);
- if (super.map[((MultiModule)this).getIndexOfSchema(var3.getFileName())] && !var3.isValid()) {
- return false;
- }
- }
-
- return true;
- }
- }
-
- public boolean isValid(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive.");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((SchemaWrapper)this.schemas.get(var1)).isValid();
- }
- }
-
- public boolean isWellFormed() throws SchemaException {
- if (((MultiModule)this).isEmpty()) {
- throw new SchemaException("There are no schemas in the archive");
- } else {
- Vector var1 = this.getSchemas();
-
- for(int var2 = 0; var2 < var1.size(); ++var2) {
- SchemaWrapper var3 = (SchemaWrapper)var1.elementAt(var2);
- if (super.map[((MultiModule)this).getIndexOfSchema(var3.getFileName())] && !var3.isWellFormed()) {
- return false;
- }
- }
-
- return true;
- }
- }
-
- public boolean isWellFormed(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive.");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((SchemaWrapper)this.schemas.get(var1)).isWellFormed();
- }
- }
-
- public Vector getValidSchemas() {
- Vector var1 = new Vector();
- Vector var2 = this.getUsedSchemas();
-
- for(int var3 = 0; var3 < var2.size(); ++var3) {
- SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
- if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && var4.isValid()) {
- var1.addElement(var4);
- }
- }
-
- return var1;
- }
-
- public Vector getNotValidSchemas() {
- Vector var1 = new Vector();
- Vector var2 = this.getUsedSchemas();
-
- for(int var3 = 0; var3 < var2.size(); ++var3) {
- SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
- if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && !var4.isValid()) {
- var1.addElement(var4);
- }
- }
-
- return var1.size() == 0 ? null : var1;
- }
-
- public Vector getWfSchemas() {
- Vector var1 = new Vector();
- Vector var2 = this.getUsedSchemas();
-
- for(int var3 = 0; var3 < var2.size(); ++var3) {
- SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
- if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && var4.isWellFormed()) {
- var1.addElement(var4);
- }
- }
-
- return var1;
- }
-
- public Vector getNotWfSchemas() {
- Vector var1 = new Vector();
- Vector var2 = this.getUsedSchemas();
-
- for(int var3 = 0; var3 < var2.size(); ++var3) {
- SchemaWrapper var4 = (SchemaWrapper)var2.elementAt(var3);
- if (super.map[((MultiModule)this).getIndexOfSchema(var4.getFileName())] && !var4.isWellFormed()) {
- var1.addElement(var4);
- }
- }
-
- return var1;
- }
-
- public Vector getNotParseable() {
- Vector var1 = new Vector(((MultiModule)this).getNotParseableCount());
-
- for(int var2 = 0; var2 < super.map.length; ++var2) {
- if (!super.map[var2]) {
- var1.addElement(this.schemas.get(super.fileNameMap[var2]));
- }
- }
-
- return var1;
- }
-
- public Vector getDeclErrors(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((MultiModule)this).retDeclErrors(var1);
- }
- }
-
- public int getDeclErrorsCount(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((MultiModule)this).retDeclErrorsCount(var1);
- }
- }
-
- public Vector getParseErrors(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((MultiModule)this).retParseErrors(var1);
- }
- }
-
- public int getParseErrorsCount(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((MultiModule)this).retParseErrorsCount(var1);
- }
- }
-
- public Vector getDeclErrorsDesc(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((MultiModule)this).retDeclErrorsDesc(var1);
- }
- }
-
- public Vector getParseErrorsDesc(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((MultiModule)this).retParseErrorsDesc(var1);
- }
- }
-
- public String getResults(String var1) throws SchemaException {
- if (!this.schemas.containsKey(var1)) {
- throw new SchemaException("Schema not found in archive");
- } else if (!super.map[((MultiModule)this).getIndexOfSchema(var1)]) {
- throw new SchemaException("Schema is not parseable");
- } else {
- return ((SchemaWrapper)this.schemas.get(var1)).getResults();
- }
- }
-
- void changedSchema(String var1) {
- if (this.used.containsKey(var1)) {
- this.used.remove(var1);
- }
-
- }
-
- private void initSchemas(boolean[] var1, String[] var2, String[] var3) throws IOException, SchemaException {
- if (var1.length != var2.length) {
- throw new SchemaException("The <Map> array and the <FileName> array must have the same size");
- } else {
- this.initSchemas(var2, var3);
- }
- }
-
- private void initSchemas(String[] var1, String[] var2) throws IOException, SchemaException {
- this.used = new Hashtable();
- if (var1.length != var2.length) {
- throw new SchemaException("The <FileName> array and the <Content> array must have the same size");
- } else {
- for(int var3 = 0; var3 < var1.length; ++var3) {
- var2[var3] = var2[var3].substring(StringUtilities.skipWhite(var2[var3], 0));
- }
-
- if (super.persistent) {
- ((MultiModule)this).saveToFile(var1, var2);
- }
-
- this.createSchemas(var1, var2);
- }
- }
-
- private void createSchemas(String[] var1, String[] var2) {
- for(int var3 = var1.length - 1; var3 >= 0; --var3) {
- try {
- this.schemas.put(var1[var3], new SchemaWrapper(new File(super.localDir, var1[var3]), this));
- } catch (Exception var5) {
- this.schemas.put(var1[var3], (Object)null);
- }
- }
-
- }
-
- private Vector getUsedSchemas() {
- return this.getSchemas(this.used);
- }
-
- private Vector getSchemas(Hashtable var1) {
- Vector var2 = new Vector(var1.size());
- Enumeration var3 = var1.elements();
-
- while(var3.hasMoreElements()) {
- var2.addElement(var3.nextElement());
- }
-
- return var2;
- }
-
- private void validateSchema(String var1, SchemaWrapper var2) {
- this.validateSchema0(var1, var2);
- this.validateInclMod(var2);
- }
-
- private void validateSchema0(String var1, SchemaWrapper var2) {
- try {
- if (!this.used.containsKey(var1)) {
- this.used.put(var1, var2);
- }
-
- var2.validate();
- super.validValues.put(var1, new Boolean(var2.isValid()));
- super.wfValues.put(var1, new Boolean(var2.isWellFormed()));
- SchemaAllErrors var3 = new SchemaAllErrors();
- if (!var2.isValid()) {
- var3.setDeclErrors(var2.getDeclErrors());
- var3.setParseErrors(var2.getParseErrors());
- var3.setDeclErrorsDesc(var2.getDeclErrorsDesc());
- var3.setParseErrorsDesc(var2.getParseErrorsDesc());
- }
-
- super.errors.put(var1, var3);
- } catch (Exception var4) {
- super.validValues.put(var1, new Boolean(false));
- super.wfValues.put(var1, new Boolean(false));
- }
-
- }
-
- private void validateInclMod(SchemaWrapper var1) {
- Vector var2 = new Vector(((MultiModule)this).size() - 1);
- Enumeration var3 = var1.getIncludedModules();
- if (var3 != null) {
- while(var3.hasMoreElements()) {
- ExternalSubset var4 = (ExternalSubset)var3.nextElement();
- String var5 = ((BaseDeclaration)var4).getName();
- if (!var2.contains(var5)) {
- var2.addElement(var5);
- SchemaWrapper var6 = (SchemaWrapper)this.schemas.get(var5);
- this.validateSchema0(var5, var6);
- }
- }
- }
-
- }
- }
-